package com.ahaoyou.datasource;

/**
 * @Description
 * @Author LH
 * @Date 2021-09-26 15:40
 */
public class DynamicDataSourceContextHolder {
    /**
     *  数据源标识保存在线程变量中，避免多线程操作数据源时互相干扰
     */
    private static final ThreadLocal<String> THREAD_DATA_SOURCE = new ThreadLocal<>();

    public static String getDataSourceKey() {
        return THREAD_DATA_SOURCE.get();
    }

    public static void setDataSource(String dataSource) {
        THREAD_DATA_SOURCE.set(dataSource);
    }

    public static void clearDataSource() {
        THREAD_DATA_SOURCE.remove();
    }
}